/*
* Copyright (C) 2021 ~ 2022 Uniontech Technology Co., Ltd.
*
* Author:      zhangbingyi <zhangbingyi@uniontech.com>
*
* Maintainer:  zhangbingyi <zhangbingyi@uniontech.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "common.h"
#include "compixmap.h"

#include <QFrame>

#include <QWidget>
#include <QThread>

namespace def {
namespace widgets {
class TitleButtonItem;
class TitledSliderItem;
class DCCSlider;
} // namespace widgets
} // namespace def

class SecurityLevelItem;
class SettingsInvokerInterface;
class SecurityLevelModel;
class ConfiguratingSystemLevelDialog;
class ExecutingDialog;

class QVBoxLayout;
class SystemLevelPolicyKit;

using namespace def::widgets;
class SecurityLevelWidget : public QFrame
{
    Q_OBJECT
public:
    explicit SecurityLevelWidget(QWidget *parent = nullptr);
    ~SecurityLevelWidget();
    void initUI();

    // 验证权限
    void verifyPermission(int nType);

    // 设置弹窗
    void showDialog(bool isResult, int type);
    // item选中图标显示
    void showSelectItemIcon(int nType);

    // 只有安全管理员才允许降级弹框
    void showSecurityAdminDialog();

public Q_SLOTS:
    // 显示三权账户密码输入弹框
    void showLevelPasswordDialog();
    // 显示开启等保正在配置弹框
    void showSystemLevelOnDialog(const QString &sSysadmPassword, const QString &sSecadmPassword, const QString &sAudadmPassword);

    // 等保开启关闭失败
    void acceptSystemLevelChangeFinish(bool isSuccess, int nType);

    // 系统安全等级切换 - 除开启/关闭等保
    void acceptSystemLevelChange();

    // 系统安全等级切换 -- 关闭等保
    void acceptSystemLevelClose();

    void highLevelItemClicked();
    void mediumLevelItemClicked();
    void lowLevelItemClicked();
    void showSelectItemIconHelp();

Q_SIGNALS:
    void requestConfirmChangeSystemLevel(int nType);

private:
    QVBoxLayout *m_layout; // 主布局器
    SecurityLevelItem *m_highLevelItem; // 高安全等级项
    SecurityLevelItem *m_mediumLevelItem; // 中安全等级项
    SecurityLevelItem *m_lowLevelItem; // 低安全等级项

    int m_nSaveItemType;
    SecurityLevelModel *m_securityLevelModel;

    ConfiguratingSystemLevelDialog *m_systemLevelStartDialog;
    ExecutingDialog *m_executingDialog;

    QThread m_polKitThread;
    SystemLevelPolicyKit *m_policyKit;
};
